'''
    删除排序链表中的重复元素
'''

# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
        if head == None:
            return None
        
        left = head
        right = head.next
        while right:
            if right.val != left.val:
                left = left.next
                left.val = right.val
            right = right.next
        left.next = None
        return head
    
    def deleteDuplicates2(self, head: Optional[ListNode]) -> Optional[ListNode]:
        if head == None:
            return None
        left = right = head
        while right:
            if right.val != left.val:
                left.next = right
                left = left.next
            right = right.next
        left.next = None
        return head
